package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//这里要生效，还得配置src/main/resources/META-INF/spring.factories
@Configuration
@ConditionalOnClass(DispatcherServlet.class)//springMvc的核心，也就是微服务（springboot项目的共同点）
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());//后面可以配置拦截路径，默认拦截所有路径.addPathPatterns()
    }
}
